package refresh

import (
	"gin_demo/utility"
	"strings"
	"time"

	"github.com/gin-gonic/gin"
)

var REfresh = ReFresh{}

type ReFresh struct{}

// @Summary token刷新接口
// @Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
// @Router  /backend/refresh [get]
// @version 1.0
func (r *ReFresh) Refresh(ctx *gin.Context) {
	token := ctx.Request.Header.Get("Authorization")
	s := utility.RefreshToken(strings.Split(token, " ")[1])
	utility.Success(ctx, map[string]interface{}{
		"token":      s,
		"expires_at": time.Now().Add(3 * time.Hour * time.Duration(1)).Unix(),
	})
}
